
package it.enea.xlab.tebes.validation.common;


import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger;

/**
 * @authors fulvio di marco, cristiano novelli
 * 
 * <p>Copyright 2009-2010 Epoca srl</p>
 * <p>Copyright 2012 Enea</p>
 */
public class PropertiesUtil {
	
	private static String PROPERTIES_FILE = "validation.properties";
	private static org.apache.commons.configuration.Configuration configuration;
	private static Logger logger = Logger.getLogger(PropertiesUtil.class.getName());

	
	
	/**
	 * Get CONFIGURATION
	 */	
	private static org.apache.commons.configuration.Configuration getConfiguration() {
		if (configuration == null) {
			try {
				configuration = new PropertiesConfiguration(PROPERTIES_FILE);
			} catch (ConfigurationException e) {
				logger.error(e.getMessage());
			}
		}
		return configuration;
	}
	
	

	
	
	/**
	 * Get PROPERTIES
	 */	
	public static String getArtifactsLocationProperty() {

		return getConfiguration().getString("artifacts.location");
	}
	
	public static String getArtifactsDirProperty() {

		return getConfiguration().getString("artifacts.dir");
	}


	public static String getArtifactsDirPath() {
		
		String artifactsPath = getArtifactsLocationProperty();	
		artifactsPath = checkFinalSlash(artifactsPath);
		
		artifactsPath = artifactsPath.concat(getArtifactsDirProperty());
		artifactsPath = checkFinalSlash(artifactsPath);
		
		return artifactsPath;
	}
	
	/**
	 * Check final SLASH
	 */	
	private static String checkFinalSlash(String path) {

		if (!path.endsWith(Constants.SLASH))
			return path.concat(Constants.SLASH);
		else
			return path;
	}

}

